/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dk.fe;

import org.netbeans.api.visual.action.ActionFactory;
import org.netbeans.api.visual.action.WidgetAction;
import org.netbeans.api.visual.anchor.Anchor;
import org.netbeans.api.visual.anchor.AnchorFactory;
import org.netbeans.api.visual.anchor.AnchorShape;
import org.netbeans.api.visual.graph.GraphScene;
import org.netbeans.api.visual.widget.ConnectionWidget;
import org.netbeans.api.visual.widget.LayerWidget;
import org.netbeans.api.visual.widget.Widget;
import org.netbeans.api.visual.widget.general.IconNodeWidget;

/**
 *
 * @author andreas
 */
public class TargetScene extends GraphScene<Target, TargetEdge>{

    private LayerWidget mainLayer;
    private Widget connectionLayer;

    public TargetScene() {
        mainLayer=new LayerWidget(this);
        addChild(mainLayer);
        connectionLayer = new Widget (this);
        addChild (connectionLayer);
    }
    
    @Override
    protected Widget attachNodeWidget(Target n) {
        IconNodeWidget widget=new IconNodeWidget(this);
        widget.setLabel(n.getName());
        widget.getActions().addAction(ActionFactory.createMoveAction());
        mainLayer.addChild(widget);
        return widget;
    }

    @Override
    protected Widget attachEdgeWidget(TargetEdge e) {
        ConnectionWidget widget = new ConnectionWidget (this);
        //widget.setTargetAnchorShape (AnchorShape.TRIANGLE_FILLED);

        WidgetAction.Chain actions = widget.getActions ();
        actions.addAction (createObjectHoverAction ());
        actions.addAction (createSelectAction ());

        connectionLayer.addChild (widget);
        return widget;
    }

    @Override
    protected void attachEdgeSourceAnchor(TargetEdge e, Target n, Target n1) {
        ConnectionWidget edgeWidget = (ConnectionWidget) findWidget (e);
        Widget sourceNodeWidget = findWidget (n1);
        Anchor sourceAnchor = AnchorFactory.createRectangularAnchor (sourceNodeWidget);
        edgeWidget.setSourceAnchor (sourceAnchor);
    }

    @Override
    protected void attachEdgeTargetAnchor(TargetEdge e, Target n, Target n1) {
        ConnectionWidget edgeWidget = (ConnectionWidget) findWidget (e);
        Widget targetNodeWidget = findWidget (n1);
        Anchor targetAnchor = AnchorFactory.createRectangularAnchor (targetNodeWidget);
        edgeWidget.setTargetAnchor (targetAnchor);
    }
    
}
